/**
 * Created by Administrator on 2017/2/16.
 */


var GlobalConfig = require('../../../../config/config.json');

module.exports = function(app) {
    return new Handler(app);
};

var Handler = function(app) {
    this.app = app;
};

var handler = Handler.prototype;

handler.getMessages = function(msg, session, next) {
    msg.nolog = true;
    var self = this;

    next(null, gGlobalManager.getConfig("content") || {});
};

handler.getOnlineCount = function(msg, session, next) {
    msg.nolog = true;
    var self = this;

    next(null, {
        onlineCount: gPlayerManger.getVirtualOnlineCount()
    })
};

/**
 * 提交反馈
 * @param msg {type:"agent申请代理|bug通用错误", content:"内容", attach:"附件"}
 * @param session
 * @param next
 */
handler.feedback = function(msg, session, next) {
    next(null, {});

    var uid = session.uid;
    gPlayerManger.getPlayer(uid, function(player) {
        if (!player) {
            next(null, {code:Code.DB_ERROR}); return;
        }

        var sql = util.format("INSERT INTO %sfeedback(uid, uname, type, content, attach, add_time, `status`) value(%d, %s, %s, %s, %s, %d, %d)",
            GlobalConfig.mysql.prefix, uid, SQL.escape(player.user.info.name), Def.Feedback[msg.type]||0, SQL.escape(msg.content), SQL.escape(msg.attach), Date.getStamp(), 0);
        SQL.query(sql, function(err, results) {
            if (err) {
                logger.error("uid=%d hallHandler.feedback sql=%s err=%j", uid, sql, err.message);
            }
        });
    });
};
//返回消息
handler.backMsg = function(msg, session, next) {
    msg.nolog = true;
    next(null, msg);
};

